/*
Copyright (C) 2009-2010 Xanadu Development Team

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include "../PacketCreator.h"
#include "../../server/Player.h"

PacketWriter* PacketCreator::showTrade(Player* right, Player* left) {
	pw.writeShort(PLAYER_INTERACTION);
	pw.write(0x05);
	pw.write(0x03);
	pw.write(0x02);
	if(left == 0) {
		pw.writeShort(0);
	} else {
		pw.write(1);
		pw.write(0);
		addCharLook(left, false);
		pw.writeString(left->getName());
		pw.write(1);
	}
	addCharLook(right, false);
	pw.writeString(right->getName());
	pw.write(-1);
	return &pw;
}

PacketWriter* PacketCreator::inviteTrade(Player* player, int inviteid) {
	pw.writeShort(PLAYER_INTERACTION);
	pw.write(0x02);
	pw.write(0x03);
	pw.writeString(player->getName());
	pw.writeInt(inviteid);
	return &pw;
}

PacketWriter* PacketCreator::joinTrade(Player* player) {
	pw.writeShort(PLAYER_INTERACTION);
	pw.write(0x04);
	pw.write(1);
	addCharLook(player);
	pw.writeString(player->getName());
	return &pw;
}

PacketWriter* PacketCreator::tradeMessage(Player* player, char type, char message) {
	pw.writeShort(PLAYER_INTERACTION);
	pw.write(type);
	pw.write(message);
	pw.writeString(player->getName());
	return &pw;
}

PacketWriter* PacketCreator::tradeError(char type, char message) {
	pw.writeShort(PLAYER_INTERACTION);
	pw.write(type);
	pw.write(0x00);
	pw.write(message);
	return &pw;
}

PacketWriter* PacketCreator::showTradeChat(string msg, bool by) {
	pw.writeShort(PLAYER_INTERACTION);
	pw.write(0x06);
	pw.write(0x08);
	pw.write(by);
	pw.writeString(msg);
	return &pw;
}

PacketWriter* PacketCreator::tradeMesos(int mesos, char side) {
	pw.writeShort(PLAYER_INTERACTION);
	pw.write(0x10);
	pw.write(side);
	pw.writeInt(mesos);
	return &pw;
}

PacketWriter* PacketCreator::tradeItem(Item* item, char side) {
	pw.writeShort(PLAYER_INTERACTION);
	pw.write(0x0F);
	pw.write(side);
	itemInfo(item, true, true);
	return &pw;
}

PacketWriter* PacketCreator::tradeConfirm() {
	pw.writeShort(PLAYER_INTERACTION);
	pw.write(0x11);
	return &pw;
}
